home *** CD-ROM | disk | FTP | other *** search
- /* PrintNCRScript.c */
- /*
- * PrintNCRScript.c
- * Copyright © 1995 Apple Computer Inc. All Rights Reserved.
- */
- /* .___________________________________________________________________________________.
- | This dumps the NCR Script. It must be run immediately after system restart. |
- | It supports only one device. |
- .___________________________________________________________________________________.
- */
- #include <NCRDriverPrivate.h>
- #include <stdio.h>
- #include <string.h>
- #define NOP 0x80000000 /* Jump never */
- #define OP_MASK (bit31 | bit30) /* Select the operator type */
- #define IO_OP (bit30)
- #define JUMP_OP (bit31)
- #define MEMORY_MOVE_OP (bit31 | bit30)
- #define OPCODE(op) ((op) & OP_MASK)
- #define IsMemoryMoveOp(op) (OPCODE(op) == MEMORY_MOVE_OP)
- #define IsLabel(op) ((op) == NOP)
-
- DriverGlobalPtr gDriverGlobalPtr;
- Boolean gScriptSetup = FALSE;
- OSErr GetDriverGlobalPtr(void);
- void PrintNCRScript(void);
- Boolean HasLabel(
- UInt32 opcode
- );
-
- void
- main(void)
- {
- OSErr status;
-
- status = GetDriverGlobalPtr();
- if (status != noErr)
- printf("Can't get Driver Global Information: status %d\n", (int) status);
- else {
- PrintNCRScript();
- }
- fclose(stdout);
- }
-
- void
- PrintNCRScript(void)
- {
- UInt32 *ncrScriptPtr;
- ByteCount ncrScriptSize;
- int i;
- short size;
- Boolean isLabel;
- UInt32 dcmd;
- UInt32 dsps;
- UInt32 temp;
- UInt32 pc;
- short opSize;
-
- printf("•\n••• SCSI Script\n•\n");
- ncrScriptPtr = gDriverGlobalPtr->ncrSCSIScript;
- ncrScriptSize = gDriverGlobalPtr->ncrSCSIScriptSize;
- size = (ncrScriptSize / sizeof (UInt32));
- printf("Script at %08lx, size %ld\n",
- (unsigned long) ncrScriptPtr,
- (signed long) ncrScriptSize
- );
- for (i = 0; i < size; i += opSize) {
- opSize = 2;
- dcmd = ncrScriptPtr[i];
- dsps = ncrScriptPtr[i + 1];
- if (gScriptSetup) {
- dcmd = (dcmd);
- dsps = EndianSwap32Bit(dsps);
- }
- if (IsMemoryMoveOp(dcmd)) {
- temp = ncrScriptPtr[i + 2];
- if (gScriptSetup)
- temp = EndianSwap32Bit(temp);
- ++opSize;
- }
- pc = (i + opSize) * sizeof (UInt32);
- printf("%03x %08lx %08lx",
- i * sizeof (UInt32),
- dcmd,
- dsps
- );
- if (IsMemoryMoveOp(dcmd))
- printf(" 08lx", temp);
- if (gScriptSetup == FALSE
- && ((dsps & 0xFF000000) >> 24) > ' '
- && ((dsps & 0xFF000000) >> 24) <= '~') {
- isLabel = (dcmd == 0x80000000);
- printf("('%.4s')%s",
- &dsps,
- (isLabel) ? " <--" : ""
- );
- }
- if (gScriptSetup && HasLabel(dcmd)) {
- printf(" -> [%03x %4d]",
- dsps + pc,
- dsps + pc
- );
- }
- printf("\n");
- }
- }
-
- /*
- * This must track HasLabel in the NCRRunScript.c
- */
- Boolean
- HasLabel(
- UInt32 opcode
- )
- {
- Boolean result;
-
- switch (opcode & (bit31 | bit30)) {
- case (0): /* 00 Block move instruction */
- result = FALSE;
- break;
- case (bit30): /* 01 I/O and read/write instructions */
- if ((opcode & (bit29 | bit28 | bit27)) == bit27)
- result = FALSE; /* 01 001 Wait Disconnect takes no label */
- else if ((opcode & (bit29 | bit28 | bit27)) <= bit29)
- result = TRUE; /* 01 000..100 are I/O instructions */
- else {
- result = FALSE; /* 01 101..111 are read/write instructions */
- }
- break;
- case (bit31): /* 10 Transfer Control instructions */
- switch (opcode & (bit29 | bit28 | bit27)) {
- case 0: /* 10 000 Jump (0x80000000 == NOP) */
- case bit27: /* 10 001 Call */
- case bit28: /* 10 010 Return */
- result = TRUE;
- break;
- case (bit28 | bit27): /* 10 011 Interrupt */
- default: /* 10 1xx Reserved */
- result = FALSE;
- break;
- }
- break;
- case (bit31 | bit30): /* 11 Memory Move */
- result = FALSE;
- break;
- }
- return (result);
- }
-
-
- /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- * TestFindDriverDeviceEntry
- *
- * Search for our driver's entry in the Name Registry. .
- */
- OSErr
- GetDriverGlobalPtr(void)
- {
- OSStatus osStatus;
- RegEntryIter cookie;
- Boolean done;
- RegEntryID deviceEntry;
- RegPropertyValueSize size;
-
- osStatus = RegistryEntryIterateCreate(&cookie);
- if (osStatus != noErr)
- fprintf(stderr, "RegistryEntryIterateCreate failed: %d\n", (int) osStatus);
- if (osStatus == noErr) {
- osStatus = RegistryEntrySearch(
- &cookie,
- kRegIterContinue,
- &deviceEntry,
- &done,
- "name",
- kPCIDeviceNameCString,
- strlen(kPCIDeviceNameCString) + 1
- );
- if (done != FALSE && osStatus == noErr)
- osStatus = paramErr;
- RegistryEntryIterateDispose(&cookie);
- } /* If we could create an iterator */
- if (osStatus != noErr)
- fprintf(stderr, "RegistryEntrySearch failed: %d\n", (int) osStatus);
- if (osStatus == noErr) {
- /*
- * We have the registry entry for our device. Get the global pointer
- */
- size = sizeof gDriverGlobalPtr;
- osStatus = RegistryPropertyGet(
- &deviceEntry,
- kDriverGlobalsPropertyName,
- (RegPropertyValue *) &gDriverGlobalPtr,
- &size
- );
- (void) RegistryEntryIDDispose(&deviceEntry);
- if (osStatus != noErr)
- fprintf(stderr, "RegistryPropertyGet failed: %d\n", (int) osStatus);
- }
- return ((OSErr) osStatus);
- }
-
-
-